<?php

namespace app\stores\model\order;

use app\common\model\CommonModel;

class ChargebackModel extends CommonModel{

    protected  $name = 'beautiful_order_chargeback';

    protected  $pk   = 'chargeback_id';



    public static function onBeforeInsert($model)
    {
        $model->set("add_time", date('Y-m-d H:i:s'));
        $model->set("add_ip", request()->ip());
    }
    public static function list($where){
        $list = self::where($where)->select()->toArray();
        return $list;
    }
    public static function getList($where,$order,$field='*'){
        $list = self::alias('c')
            ->field($field)
            ->order($order)
            ->join('beautiful_order_item i','c.order_item_id=i.order_item_id')
            ->leftjoin('beautiful_goods g','g.goods_id=i.goods_id')
            ->leftjoin('beautiful_goods_other_sku_detail d','g.unit_id=d.other_sku_detail_id')
            ->where(['c.is_delete'=>0])
            ->when(isset($where['order_id']),function ($query) use ($where){
                $query->where(['c.order_id'=>$where['order_id']]);
            })
            ->select()->toArray();
        return $list;
    }
}



